import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:top_foundation/utils/ex/image.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/component/component.dart';

import '../../../helper/component/base/casstle/index.dart';
import '../../../helper/utils/util.dart';
import 'index.dart';

class CasstleDemo_2Page extends CasstlePage<CasstleDemo_2Controller> {
  const CasstleDemo_2Page({Key? key}) : super(key: key);

  @override
  bool? get refreshOnHeaderTop => true;

  @override
  Widget buildUpdateTabBar(BuildContext context, bool isFloat) {
    return Container(
        color: Colors.white, child: super.buildUpdateTabBar(context, isFloat));
  }

  @override
  List<Widget> buildHeaderSliver(
      BuildContext context, bool innerBoxIsScrolled) {
    final state = controller.state;
    return [
      SliverToBoxAdapter(
        child: CarouselSlider.builder(
          itemCount: state.carouselList.length,
          options: CarouselOptions(
            // reverse: true,
            enlargeCenterPage: true,
            viewportFraction: 1,
          ),
          itemBuilder:
              (BuildContext context, int itemIndex, int pageViewIndex) =>
                  IImage.net(
                      url: state.carouselList[itemIndex],
                      fit: BoxFit.cover,
                      width: 1.sw),
        ),
      ),
      SliverPersistentHeader(
          pinned: true,
          floating: true,
          delegate: TPSliverPersistentHeaderDelegate(
              builder: (isFloat) {
                return buildUpdateTabBar(context, isFloat);
              },
              max: 44.r,
              min: 44.r)),
    ];
  }

  @override
  Widget indexPageBuilder(BuildContext context, int index,
      {ScrollPhysics? physics}) {
    return MediaQuery.removePadding(
      context: context,
      removeTop: true, //去除顶部的空白
      child: ListView.builder(
        physics: physics,
        padding: EdgeInsets.symmetric(horizontal: 12.r),
        itemBuilder: (context, i) {
          return TitleContentItemView(
            title: '第$index个页面--第$i行',
            border: Border(
              bottom: ITheme.borderSide,
            ),
          );
        },
        itemCount: 30,
      ),
    );
  }

  @override
  Widget buildView(BuildContext context, Widget refreshBody) {
    return Scaffold(
      appBar: detailAppBar(context),
      body: refreshBody,
    );
  }
}
